#include "dlg_setting.h"
#include "ui_dlg_setting.h"

Dlg_Setting::Dlg_Setting(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::Dlg_Setting)
{
    ui->setupUi(this);
}

Dlg_Setting::~Dlg_Setting()
{
    delete ui;
}

void Dlg_Setting::showEvent(QShowEvent *event)
{
    ui->cb_ips->clear();
    auto l = QNetworkInterface::allAddresses();
    for(auto add:l)
    {
        //qDebug()<<add.toString();

        if(QAbstractSocket::IPv4Protocol == add.protocol())
        {
            ui->cb_ips->addItem(add.toString());
        }
    }
}

QString Dlg_Setting::getLocalIP()
{
    return ui->cb_ips->currentText();

}

QString Dlg_Setting::getServerIP()
{
    return ui->le_server->text();
}

QString Dlg_Setting::getName()
{
    return ui->le_name->text();
}

int Dlg_Setting::getServerPort()
{
    return ui->le_port->text().toInt();
}

void Dlg_Setting::on_btn_ok_clicked()
{
    emit cnt();
    this->done(1);
}

void Dlg_Setting::on_btn_cancel_clicked()
{
    this->done(0);
}

